package cn.qianyan.controllers;

import cn.qianyan.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:
 * @createDate:
 * @description:
 */

@Controller
@ResponseBody
@RequestMapping("home")
public class homeController {

    @Autowired
    private HomeService homeService;

    @RequestMapping("showAll")
    public Map showAll(){
        Map map = new HashMap();
        map.put("alertNum",homeService.countAlert());//放入此时报警数
        map.put("normalNum",homeService.countNormal());//放入此时正常数

        //处理十二月份的数据
        int Jan = 0; int Feb = 0; int Mar = 0; int Apr = 0;
        int May = 0; int Jun = 0; int Jul = 0; int Aug = 0;
        int Sep = 0; int Oct = 0; int Nov = 0; int Dec = 0;
        List<Integer> months = homeService.selectAlertNumByMonth();
        for (int i=0;i<months.size();i++){
            if(months.get(i)==1){ Jan = Jan+1; }
            if(months.get(i)==2){ Feb = Feb+1; }
            if(months.get(i)==3){ Mar = Mar+1; }
            if(months.get(i)==4){ Apr = Apr+1; }
            if(months.get(i)==5){ May = May+1; }
            if(months.get(i)==6){ Jun = Jun+1; }
            if(months.get(i)==7){ Jul = Jul+1; }
            if(months.get(i)==8){ Aug = Aug+1; }
            if(months.get(i)==9){ Sep = Sep+1; }
            if(months.get(i)==10){ Oct = Oct+1; }
            if(months.get(i)==11){ Nov = Nov+1; }
            if(months.get(i)==12){ Dec = Dec+1; }
        }
        map.put("Jan",Jan);map.put("Feb",Feb);map.put("Mar",Mar);map.put("Apr",Apr);
        map.put("May",May);map.put("Jun",Jun);map.put("Jul",Jul);map.put("Aug",Aug);
        map.put("Sep",Sep);map.put("Oct",Oct);map.put("Nov",Nov);map.put("Dec",Dec);

        map.put("VariousDevAlert",homeService.AllDevAlertNum());//各设备报警数
        map.put("VariousRegionAlert",homeService.AlertNumByRegion());//各地域报警数
        return map;
    }
}
